package com.yc.springmvc;

import com.yc.springmvc.controller.LoginInterceptor;
import com.yc.springmvc.controller.SqlDateConvertor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.*;

import java.util.Date;

@Configuration
@ComponentScan("com.yc.springmvc")
@EnableWebMvc
public class MVCConfig implements WebMvcConfigurer {

//    @Override
//    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
//        configurer.enable();
//    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("file:/F:/上课视频/135/gitee 组员" +
                        "/yc135/SpringMVC/src/main/webapp/");
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:F:/上课视频/135/0402/");
    }

    @Bean
    public MultipartResolver multipartResolver(){
        return new StandardServletMultipartResolver();
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        //registry.removeConvertible(String.class, Date.class);
        registry.addConverter(new SqlDateConvertor());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/B.html","/C.html","/uploadfile");
    }
}
